﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GenericValidation;
using System.Reflection;
using GenericValidation.Sample.Resources;
using GenericValidation.Validators;
using GenericValidation.Sample.Model;

namespace GenericValidation.Sample.Validation
{
    public class UserValidation : Validation<User>
    {
        public UserValidation()
        {
            LocalizeMembers(Members.ResourceManager);

            Member(p => p.Age)
                .IsLowerThan(10)
                .Always();

            Member(p => p.UserName)
                .IsRequired()
                .OnInsert();

            Member(p => p.UserName)
                .IsLengthLowerThan(20)
                .Always();

            IsValid(p => p.Age != null)
                .Always();

            IsValid(p => p.UserName != p.FullName)
                .Message("CustomUserNameValidation", p => p.UserName, p => p.UserName)
                .Always();
        }
    }
}
